package com.sky.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * CLassName: DishRedisCacheCleanAspect
 * Description:
 *
 * @Author: Q
 * @Create: 2025/2/18 10:45
 * @Version: 1.0
 */

@Aspect
@Component
@Slf4j
public class DishRedisCacheCleanAspect {
    @Autowired
    private RedisTemplate redisTemplate;

    @Pointcut("execution(* com.sky.controller.admin.DishController.*(..)) && @annotation(com.sky.annotation.DishRedisCacheClean)")
    public void DishRedisCacheCleanPointCut() {

    }

    @After("DishRedisCacheCleanPointCut()")
    public void cleanCache(JoinPoint joinPoint) {
        Set keys = redisTemplate.keys("dish_*");
        redisTemplate.delete(keys);
    }
}
